package cn.com.baiwei.controller;

import cn.com.baiwei.pojo.FoodStuff;
import cn.com.baiwei.service.impl.FoodStuffServiceImpl;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;

/**
 * (FoodStuff)表控制层
 *
 * @author X_Q
 * @since 2021-09-13 17:29:30
 * @version 1.0
 */
@RestController
@RequestMapping("/foodStuff")
@Api(value = "菜品(FoodStuff)管理",tags = "菜品(FoodStuff)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class FoodStuffController {
    /**
     * 服务对象
     */
    @Resource
    private FoodStuffServiceImpl foodStuffServiceImpl;

   /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @param foodName  模糊查询的内容
     * @return 单条数据
     */
/**   @RequestMapping(value = "/selectForPage", method = RequestMethod.GET)
    @ApiOperation(value = "菜品列表查询分页",notes = "列表查询分页",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "foodName",value = "菜品名称",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectForPage(@RequestParam(name = "page") int index, String foodName) {
        return this.foodStuffServiceImpl.selectForPage(index, foodName);
    }*/
    
    /**
     * 查询所有数据
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有,并模糊查询菜名数据",notes = "查询所有,并模糊查询菜名数据",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "foodName",value = "菜品名称",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectAll(String foodName) {
        return this.foodStuffServiceImpl.selectAll(foodName);
    }

    /**
     * 查询 状态1 所有数据
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAllByState", method = RequestMethod.GET)
    @ApiOperation(value = "查询状态为1的数据",notes = "查询状态为1的数据",httpMethod = "GET")
    public Map<String, Object> selectAllByState() {
        return this.foodStuffServiceImpl.selectAllByState();
    }
    
    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    @ApiOperation(value = "根据主键id删除一条菜品记录",notes = "根据主键id删除一条菜品记录",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> deleteById(@RequestParam("id") String id) {
        return this.foodStuffServiceImpl.deleteById(id);
    }
    
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    @ApiOperation(value = "主键id查询一个菜品",notes = "通过主键id查询一个菜品",httpMethod = "GET")
    public Map<String, Object> selectById(@RequestParam("id") Integer id) {
        return this.foodStuffServiceImpl.selectById(id);
    }
    
    /**
     * 通过主键更新单条数据
     *
     * @param foodStuff 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    @ApiOperation(value = "通过主键更新一个菜品的接口",notes = "通过主键更新一个菜品的接口",httpMethod = "POST")
    public Map<String, Object> updateById(@RequestBody @ApiParam(name = "foodStuff",value = "pojo模型",required = true) FoodStuff foodStuff) {
        return this.foodStuffServiceImpl.updateById(foodStuff);
    }
    
    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param foodStuff 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "新增一个菜品",notes = "新增一个菜品的",httpMethod = "POST")
    public Map<String, Object> insert(@RequestBody @ApiParam(name = "foodStuff",value = "pojo模型",required = true) FoodStuff foodStuff) throws IOException {
        return this.foodStuffServiceImpl.insert(foodStuff);
    }

    @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
    @ApiOperation(value = "修改菜品图片接口",notes = "菜品图片上传")
    public Map<String ,Object> uploadPicture(@RequestParam("id") Integer id, MultipartFile file, HttpServletRequest request)throws SQLException, IOException, ClassNotFoundException{
        return foodStuffServiceImpl.uploadPicture(id,file,request);
    }

    @RequestMapping(value = "/uploadState", method = RequestMethod.POST)
    @ApiOperation(value = "修改菜品状态接口",notes = "修改状态1/0")
    public Map<String ,Object> uploadState(@RequestParam("state")Integer state,@RequestParam("id") Integer id) {
        return foodStuffServiceImpl.uploadState(state,id);
    }

/*
    @RequestMapping(value = "/updateCutByIds", method = RequestMethod.POST)
    @ApiOperation(value = "批量计算",notes = "批量计算测试")
    public Map<String ,Object> updateCutByIds(@RequestBody List<OrderFormParticulars> ofpList){
        return foodStuffServiceImpl.updateCutByIds(ofpList);
    }
*/


}